package _022_1_30

import "container/list"

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func checkIsPair(layerTree []*TreeNode) bool {

	for i := 0; i < len(layerTree)/2; i++ {
		if layerTree[i] != layerTree[len(layerTree)-1-i] {
			return false
		}
	}
	return true
}

func isSymmetric(root *TreeNode) bool {
	treeNodeList := list.New()
	treeNodeList.PushBack(root)
	treeNodeList.PushBack(root)
	for treeNodeList.Len() != 0 {
		nodeL := treeNodeList.Front()
		if nodeL != nil {
			treeNodeList.Remove(nodeL)
		}
		nodeR := treeNodeList.Front()
		if nodeL != nil {
			treeNodeList.Remove(nodeR)
		}
		if nodeL == nil && nodeR == nil {
			continue
		}

		if nodeL == nil || nodeR == nil {
			return false
		}

		if nodeL.Value.(*TreeNode).Val != nodeL.Value.(*TreeNode).Val {
			return false
		}

		treeNodeList.PushBack(nodeL.Value.(*TreeNode).Left)
		treeNodeList.PushBack(nodeR.Value.(*TreeNode).Right)
		treeNodeList.PushBack(nodeR.Value.(*TreeNode).Left)
		treeNodeList.PushBack(nodeL.Value.(*TreeNode).Right)

	}

	return true

}
